/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <lib3d/model/ModelInHardware.h>
#include "Model.h"
#include "Factory.h"
#include <CompilerFeatures.h>

namespace liba {
namespace lib3d {
namespace node {

class ModelMorph : public Model
{
	NODE_DEFINITION(ModelMorph)
public:
	static const Atom node_name;
	// attribtues
	static const Atom morph_weight_name;

	ModelMorph( const Atom & name, Node * parent );
	ModelMorph(const ModelMorph& rhs);
	virtual ~ModelMorph();
	virtual ModelMorph * Clone();

//	virtual bool render( hard::Hardware * hardware, const CameraDesc & camera_desc );
	virtual void RenderToList( hard::Hardware * hardware, hard::RenderList * render_list ) LIBA_OVERRIDE;
protected:
	virtual bool on_attribute( xml::Provider * prov, const std::string & name, const std::string & value ) LIBA_OVERRIDE;
private:
	properties::DependencyProperty<double> morphWeight;
/*	SharedPrecached<filesystem::String, model::ModelInHardware> normal_model;
	SharedPrecached<filesystem::String, model::ModelInHardware> shadow_model;

	SharedPrecached<filesystem::String, model::ModelInHardware> normal_model2;
	SharedPrecached<filesystem::String, model::ModelInHardware> shadow_model2;
*/

	class HaMod :
		public HardwareDependentObject<hard::Manager, model::ModelInHardwareObject>
	{
	protected:
		virtual void on_add_hardware(hard::Manager::hardware_type * ha) LIBA_OVERRIDE;
	public:
		~HaMod();
		HaMod();
		HaMod(const HaMod & other);
	};

	HaMod normal_dst;

	SharedPrecached<filesystem::String, model::Model> normal_model_src1;
	SharedPrecached<filesystem::String, model::Model> normal_model_src2;

	SimpleArray< float > dst_positions;
	SimpleArray< float > dst_normals;
	SimpleArray< float > dst_uv0s;

	bool difference_calculated;
	double calculated_morph_weight;
};

} // namespace node
} // namespace lib3d
} // namespace liba
using namespace liba;
